#define __UART_C__
#include "uart.h"



/*
function: 2ms timer initialize
*/

void uart_init(void)
{
	U16 i=0;
	/*open the SCI*/
	SYSTEM.MSTPCRB.BIT.MSTPB29 =0;
	/* SCK as io*/
	SCI2.SCR.BYTE = 0x1;
	
	/*clk=50M/64 8 bit 2 stop no p*/
	SCI2.SMR.BYTE = 0xA;
	
	SCI2.SCMR.BYTE = 0xF2;
	/*baud= 4800*/
	SCI2.BRR = 19;
	i=65535;
	while(--i!=0);
	while(--i!=0);
	/*clr ir flag*/
	IR(SCI2,RXI2) = 0;
	IR(SCI2,TXI2) = 0;
//	IR(SCI2,TEI2) = 0;
	IR(SCI2,ERI2) = 0;
	/*open ir flag*/
	IPR(SCI2,RXI2) = 1;
	IPR(SCI2,TXI2) = 1;
	IPR(SCI2,TEI2) = 0;
	IPR(SCI2,ERI2) = 1;
	/*enable interrupt*/
	IEN(SCI2,RXI2) = 1;
	IEN(SCI2,TXI2) = 1;
	IEN(SCI2,TEI2) = 0;
	IEN(SCI2,ERI2) = 1;

	SCI2.SCR.BIT.TE = 1;
	SCI2.SCR.BIT.RE = 1;
	SCI2.SCR.BIT.TIE = 1;
	SCI2.SCR.BIT.RIE = 1;
	SCI2.SCR.BIT.TEIE = 0;
}
void clr_uart2_errfg(void)
{
	SCI2.SSR.BIT.FER= 0x0;
	SCI2.SSR.BIT.ORER= 0x0;
	SCI2.SSR.BIT.PER= 0x0;
}

